package com.holly.unit.deform.modular.pojo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.holly.unit.core.pojo.request.BaseRequest;
import com.holly.unit.deform.entity.DesignForm;
import com.holly.unit.query.api.context.QueryApiContext;
import com.holly.unit.scanner.api.annotation.field.ChineseDescription;

import java.util.Date;
import java.util.Map;

/**
 * 类描述: 表单设计基本信息参数包装类
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/8 9:55
 */
public class DesignFormRequest extends BaseRequest {

    /** ID */
    @ChineseDescription("ID")
    private String id;
    /** 表单编码 */
    @ChineseDescription("表单编码")
    private String desformCode;
    /** 表单名称 */
    @ChineseDescription("表单名称")
    private String desformName;
    /** 表单图标 */
    @ChineseDescription("表单图标")
    private String desformIcon;
    /** 表单设计JSON */
    @ChineseDescription("表单设计JSON")
    private String desformDesignJson;
    /** 绑定的 CgformCode */
    @ChineseDescription("绑定的 CgformCode")
    private String cgformCode;
    /** 父表单id */
    @ChineseDescription("父表单id")
    private String parentId;
    /** 父表单Code */
    @ChineseDescription("父表单Code")
    private String parentCode;
    /** 表单类型，1=主表，2=子表 */
    @ChineseDescription("表单类型，1=主表，2=子表")
    private Integer desformType;
    /** is oa show */
    @ChineseDescription("is oa show")
    private Boolean izOaShow;
    /** 是否是移动视图（1=是，0或null=否），一个 desform 只能有一个移动视图 */
    @ChineseDescription("是否是移动视图（1=是，0或null=否），一个 desform 只能有一个移动视图")
    private Integer izMobileView;
    /** 创建人 */
    @ChineseDescription("创建人")
    private String createBy;
    /** 创建时间 */
    @ChineseDescription("创建时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /** 修改人 */
    @ChineseDescription("修改人")
    private String updateBy;
    /** 修改时间 */
    @ChineseDescription("修改时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    /** 是否是Online表单，1 数据库表单，2 自动生成表单 */
    private Integer type;


    private Map<String,String[]> param;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDesformCode() {
        return desformCode;
    }

    public void setDesformCode(String desformCode) {
        this.desformCode = desformCode;
    }

    public String getDesformName() {
        return desformName;
    }

    public void setDesformName(String desformName) {
        this.desformName = desformName;
    }

    public String getDesformIcon() {
        return desformIcon;
    }

    public void setDesformIcon(String desformIcon) {
        this.desformIcon = desformIcon;
    }

    public String getDesformDesignJson() {
        return desformDesignJson;
    }

    public void setDesformDesignJson(String desformDesignJson) {
        this.desformDesignJson = desformDesignJson;
    }

    public String getCgformCode() {
        return cgformCode;
    }

    public void setCgformCode(String cgformCode) {
        this.cgformCode = cgformCode;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getParentCode() {
        return parentCode;
    }

    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }

    public Integer getDesformType() {
        return desformType;
    }

    public void setDesformType(Integer desformType) {
        this.desformType = desformType;
    }

    public Boolean getIzOaShow() {
        return izOaShow;
    }

    public void setIzOaShow(Boolean izOaShow) {
        this.izOaShow = izOaShow;
    }

    public Integer getIzMobileView() {
        return izMobileView;
    }

    public void setIzMobileView(Integer izMobileView) {
        this.izMobileView = izMobileView;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public Map<String, String[]> getParam() {
        return param;
    }

    public void setParam(Map<String, String[]> param) {
        this.param = param;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    // 处理方法
    public QueryWrapper<DesignForm> handleQueryWrapper() {
        DesignForm designForm = new DesignForm();
        BeanUtil.copyProperties(this,designForm);
        QueryWrapper<DesignForm> queryWrapper = QueryApiContext.me().initQueryWrapper(designForm, param);
        return queryWrapper;
    }

    public boolean hasParentId() {
        String[] parentId = param.get("parentId");
        boolean hasParentId = (parentId != null && parentId.length > 0 && !StrUtil.isEmpty(parentId[0]));
        return hasParentId;
    }


}
